/*
 * @Author: your name
 * @Date: 2020-11-14 08:37:28
 * @LastEditTime: 2021-04-05 13:43:47
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \HDZP\HDY-Perfect\src\store\reducer.js
 */

import {
  GET_ADDRESS,
  UPDATE_DEFAULT_ADDRESS,
  SELECTED_ADDRESS,
  UPDATE_APP_CONFIG,
  UPDATE_AVATAR,
  UPDATE_HOME_NOTICE_BAR,
  UPDATE_SUBMIT_CONFIG,
  PUSH_ORDER,
} from './constants'


// const env = process.env.NODE_ENV === 'development' ? true : false;
// env ? { uniacid:"1266", isApplys:1, username:'多半', isApplet:false } 

const defaultState = {
  //  store 中的一个初始化的state
  addressList: [],
  defaultAddress: {},
  selectedAddress: {},
  appConfig: {
    isBind: false
  },
  avatar: 'https://res.lexiangpingou.cn/images/826/2020/10/sfsS3P2SopR32o5SSOkhp23KkSh2YK.png',
  homeNoticeBarStatus: true,
  submitConfig: {},
  order:{
    orderno: null,
    acceptableTime: null,
    loadage: null,
    remark: "",
    isRead: false,
    agree: false
  }, // 缓存订单
}

function reducer(state = defaultState, action) {
  //  reducer 是一个纯函数
  switch (action.type) {
    case GET_ADDRESS:
      return { ...state, addressList: action.data }
    case UPDATE_DEFAULT_ADDRESS:
      return { ...state, defaultAddress: action.data }
    case SELECTED_ADDRESS:
      return { ...state, selectedAddress: action.data }
    case UPDATE_APP_CONFIG:
      return { ...state, appConfig: action.data }
    case UPDATE_AVATAR:
      return { ...state, avatar: action.data }
    case UPDATE_HOME_NOTICE_BAR:
      return { ...state, homeNoticeBarStatus: action.status }
    case UPDATE_SUBMIT_CONFIG:
      return { ...state, submitConfig: action.data }
    case PUSH_ORDER:
      return { ...state, order: action.data }
    default:
      return state;
  }

}

export default reducer;